package com.liupf.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.log4j.Logger;


public class TimeUtil
{
	
	@SuppressWarnings("unused")
	private static final Logger log = Logger.getLogger(TimeUtil.class);
	
	
	public static Date parse(String str, String format, Date defaultValue)
	{
		try
		{
			SimpleDateFormat sdf = new SimpleDateFormat(format);
			Date date = sdf.parse(str);
			return date;
		}
		catch (Exception e)
		{
			return defaultValue;
		}
	}
	
	public static String format(Date date, String format)
	{
		String str = DateFormatUtils.format(date, format);
		return str;
	}
	
	//预约订单返回true
    public static boolean compareTime(String pointT){
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try{
            Date pointD=sdf.parse(pointT);
            long time1=pointD.getTime();
            long time2=new Date().getTime();
            if(time1<time2)
                return false;
            long min=((time1-time2)/1000)/60;
            if(min>20)
                return true;
        }catch(Exception e){
            return false;
        }
        return false;
    }
}
